<template>
  <el-card class="buyGoodsList">
    <!-- 查询部分 -->
    <div class="searchForm">
      <el-form :inline="true" :model="searchForm" size="mini">
        <el-form-item label="名称">
          <el-input v-model="searchForm.p" placeholder="请输入" @keyup.enter.native="m_handleFilter"></el-input>
        </el-form-item>
        <el-form-item label="角色">
          <el-input v-model="searchForm.type" placeholder="请输入" @keyup.enter.native="m_handleFilter"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="m_handleFilter">查询</el-button>
          <el-button type="primary" @click="m_handleClear">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="hh-btnbox">
      <el-button size="mini" @click="handleAddGoods">选择商品</el-button>
      <el-button size="mini" @click="handleCart">购物车</el-button>
    </div>
    <!-- 查询部分！！！ -->

    <!-- 列表 -->
    <div class="table-box">
      <el-table
        ref="multipleTable"
        :data="tableData.list"
        highlight-current-row
        style="width: 100%"
        border
        size="mini"
        stripe
        @selection-change="m_handleSelectionChange"
      >
        <el-table-column align="center" width="55" type="selection" fixed="left"></el-table-column>
        <el-table-column align="center" type="index" width="50" label="序号"></el-table-column>
        <el-table-column
          v-for="item in tableData.headList"
          :key="item.name"
          :label="item.title"
          :prop="item.name"
          :show-overflow-tooltip="true"
          align="center"
        >
          <template slot-scope="scope">
            <div v-if="item.name=='images'"></div>
            <div v-else>{{scope.row[item.name]}}</div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="tableData.total>0"
        :total="tableData.total"
        :page.sync="searchForm.start"
        :limit.sync="searchForm.count"
        @pagination="m_getTableData"
      />
    </div>
    <!-- 列表 -->
  </el-card>
</template>


<script>
import { goodsList } from "@/api/product";
import { axiosAddShoppingCart } from "@/api/shoppingCart.js";
import tablePage from "@/mixins/tablePage";
import pagination from "@/components/Pagination";
export default {
  name: "buyGoodsList",
  mixins: [tablePage],
  components: {
    pagination
  },
  data() {
    return {
      searchForm: {
        //搜索数据
        start: 1,
        count: 10
      },
      fn: goodsList,
      tableData: {
        //表格数据
        headList: [
          {
            name: "goodsName",
            title: "产品名称"
          },
          {
            name: "coding",
            title: "产品代码"
          },
          {
            name: "price",
            title: "产品价格"
          },
          {
            name: "stockNum",
            title: "产品库存"
          }
        ],
        list: [],
        total: 0
      },
      rows: {} //表行
    };
  },
  computed: {},
  created() {
    this.m_getTableData();
  },
  methods: {
    handleAddGoods() {
      const goodsIds = this.multipleSelection.map(item => {
        return item.id;
      });
      let str = JSON.stringify(goodsIds);
      axiosAddShoppingCart({
        goodsIds: str
      });
    },
    handleCart(){
      this.$emit('buyShow')
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.buyGoodsList {
}
</style>
